package com.xyc.servlet.main;

import com.xyc.mapper.SongMapper;
import com.xyc.pojo.Song;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/mySong")
public class MySongServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        SongMapper songMapper = ctx.getBean("songMapper", SongMapper.class);
        List<Song> songList = songMapper.selectSong();
        req.setAttribute("songList", songList);
        req.getRequestDispatcher("user/mySong.jsp").forward(req, resp);
    }
}
